package ar.unc.famaf.pln.giveselector.pickers;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import ar.unc.famaf.pln.giveselector.classifier.IClassifier;
import ar.unc.famaf.pln.giveselector.classifier.UtteranceComparator;
import ar.unc.famaf.pln.giveselector.classifier.UtteranceP;
import ar.unc.famaf.pln.giveselector.context.Utterance;

/**
 * Picks the Utterance which the highest performance score.
 * 
 * @author David Racca ( david.racca@gmail.com )
 *
 */
public class PMemoryPicker extends MemoryPicker {

	private IClassifier classifier;
	private Comparator<Utterance> comparator;


	public PMemoryPicker(IClassifier classifier)
	{
		this.classifier = classifier;
		this.comparator = Collections.reverseOrder(new UtteranceComparator(classifier));
	}

	protected List<Utterance> sort(Set<Utterance> utterances)
	{
		List<Utterance> ret = new ArrayList<Utterance>(utterances);
		Collections.sort(ret, comparator);
		for (Utterance u : ret)
			System.out.println("Score: " + ((u instanceof UtteranceP) ? classifier.getScore(u) : "n/i") 
					+ " [" + u.getId() + "] " + u.getText());

		return ret;
	}

}
